##########################################################
# John Henderson and Alex Theodoridis
# Replication Data for: "Seeing Spots", 
#  Forthcoming in Political Behavior, August 20, 2017
# 
##########################################################
#
#  figure_vii.R
#  -- file produces the density plots Figure vii in appendix
#
##########################################################

rm(list=ls())
source('~/Dropbox/Seeing_Spots/replication/pre_data_vagov.R')
                 
newsint_old = newsint - 2 
#newsint = (rowSums(cbind(sen_majority_correct,hou_majority_correct,(newsint+1))))-2    
newsint_alt = rowSums(cbind(sen_majority_correct,hou_majority_correct))-1 #,(newsint+1))))-2    
#newsint[which(newsint<0)] = -1
#newsint[which(newsint>0)] =  1

college=as.numeric(va_data$educ)
college[which(as.numeric(va_data$educ)<3)]=-1
college[which(as.numeric(va_data$educ)==3 | as.numeric(va_data$educ)==4)]=0
college[which(as.numeric(va_data$educ)>4)]=1

newsint_edu = college

# density plots - interesteds

completes = !is.na(time_watched) & !is.na(pid_lean) & !is.na(newsint_old)

ytime 			= time_watched[completes] 
tr_pos_ad 		= pos_ad[completes] 
tr_neg_ad    	= neg_ad[completes] 
tr_dem_ad   	= dem_ad[completes] 
tr_rep_ad  	= rep_ad[completes] 
tr_dem_pos	= pos_ad[completes] 
tr_dem_neg  	= neg_ad[completes] 
tr_rep_pos 	= dem_ad[completes] 
tr_rep_neg 	= rep_ad[completes] 
pid				= pid_lean[completes] 
newsint_alt		= newsint_alt[completes] 
newsint_old		= newsint_old[completes] 
newsint_edu		= newsint_edu[completes] 

#lows = newsint_old==-1
#meds = newsint_old== 0
#high = newsint_old== 1       

lows = newsint_alt==-1
meds = newsint_alt== 0
high = newsint_alt== 1

                     
dems = pid==-1
inds = pid== 0
reps = pid== 1    


# pos v. neg
{                                        
pdf(file='~/Dropbox/Seeing_Spots/replication/figures/density_time_by_tone_VA_both.pdf')
plot(density(ytime[tr_pos_ad],from=0,to=100),main='',xlab='Time Watched',ylim=c(0,.09),col='black',lwd=2)  
lines(density(ytime[tr_neg_ad],from=0,to=100),main='',xlab='Time Watched',lty=2,col='black',lwd=2)      
legend(cex=1.45,x=c(1),y=c(.08),legend=c('Positive Ad'),lty=c(1),box.col="#0000ff00",col='black',lwd=2)  
legend(cex=1.45,x=c(1),y=c(.075),legend=c('Negative Ad'),lty=c(2),box.col="#0000ff00",col='black',lwd=2)

ksp=round(ks.test(c(ytime[tr_pos_ad]),ytime[c(tr_neg_ad)])$p.value,digits=3)
tp=round(t.test(c(ytime[tr_pos_ad]),ytime[c(tr_neg_ad)])$p.value,digits=3)  

text(cex=1.45,x=c(86),y=c(.085),label=c(expression(italic(paste(p,' = ',0.181),sep=''))),
  col='black',lwd=2)
dev.off()
}


# END figure_vii.R